<?php


namespace app\crontab\controller\once;


use custom\Mongo;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 入学节点映射
 * Class SchoolTimelines
 * @package app\crontab\controller
 */
class SchoolTimelines extends Command {

    //wx_xqf_cz_details_data
    public static $setName = 'wx_xqf_cz_details_data';
    public static $type = 2;

    protected function configure() {
        $this->setName('SchoolTimelines');
    }

    protected function execute(Input $input, Output $output) {
        echo "start\n";
        $mongo = Mongo::getInstance();
        $int = 7547;
        $options = [
            'projection' => ['_id' => 1, 'timelines' => 1],
            'sort'       => ['id' => 1],
        ];
        $cursor = $mongo->select(self::$setName, [], $options);
        foreach ($cursor as $v1) {
            $v1 = (array)$v1;
            if ($v1['timelines']) {
                foreach ($v1['timelines'] as $v2) {
                    $timeline_name = $v2->timeline_name;
                    $time_str = $v2->time_str;
                    $mongo->add(
                        [
                            '_id'           => (int)$int,
                            'school_id'     => (string)$v1['_id'],
                            'school_type'   => (string)self::$type,
                            'timeline_name' => (string)$timeline_name,
                            'time_str'      => (string)$time_str,
                        ],
                        'SchoolTimelines'
                    );
                    $int++;
                }
            }
        }
        echo "end\n";
    }

}